package com.zx.controller;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zx.model.user.User;
import com.zx.service.dj.RoleManageService;
import com.zx.service.user.UserService;  
  
/**
 * 
 * @author zx
 * @author yt
 *
 */
@Controller
@RequestMapping("login")
public class LoginController extends BaseController{
    
    @Resource  
    private UserService userService;
    
    @Autowired 
    private RoleManageService RoleManageService;
      
    @RequestMapping("toLogin")
    public String toLogin(Model model){
        return "dj/login";
    }
    
    @RequestMapping("showIndex")
    public String getIndex(Model model,
            @RequestParam(defaultValue="", required=false)String name,
            @RequestParam(defaultValue="", required=false)String password
            ){
        User user = RoleManageService.selRole(name);
        if(user != null && user.getPassword().equals(password)){
            model.addAttribute("user", user);
            session.setAttribute("userInfo", user);
            return "dj/top";
        }else{
            model.addAttribute("errorMsg","密码不对");
            return "dj/login";
        }
    }
    
    @RequestMapping("logout")  
    public String logout(){
        session.removeAttribute("userInfo");
        return "dj/login";  
    }  
}